/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects.smartidlc.model;

import java.util.ArrayList;
import java.util.Collection;

public class IDLInterfaceOperation {
	private String name;
	private String signature;
	private IDLInterface declaredInInterface;
	private boolean resultSessionId = false;
	
	private IDLDataType resultType;
	
	private Collection<IDLInterfaceOperationParam> params = new ArrayList<IDLInterfaceOperationParam>();
	private Collection<String> throwsDeclLinks = new ArrayList<String>();
	private Collection<IDLException> throwsDecl = new ArrayList<IDLException>();
	

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setResultType(IDLDataType resultType) {
		this.resultType = resultType;
	}

	public IDLDataType getResultType() {
		return resultType;
	}
	
	public boolean isInterfaceReferenceResult() {
		if ( this.resultType!=null && this.resultType.getUserObject() !=null && this.resultType.getUserObject() instanceof IDLInterface )
			return true;
		else
			return false;
	}
	

	public void setResultSessionId(boolean resultSessionId) {
		this.resultSessionId = resultSessionId;
	}

	public boolean isResultSessionId() {
		return resultSessionId;
	}

	public void setParams(Collection<IDLInterfaceOperationParam> params) {
		this.params = params;
	}

	public Collection<IDLInterfaceOperationParam> getParams() {
		return params;
	}
	
	public void setThrowsDeclLinks(Collection<String> throwsDeclLinks) {
		this.throwsDeclLinks = throwsDeclLinks;
	}

	public Collection<String> getThrowsDeclLinks() {
		return throwsDeclLinks;
	}

	public void setThrowsDecl(Collection<IDLException> throwsDecl) {
		this.throwsDecl = throwsDecl;
	}

	public Collection<IDLException> getThrowsDecl() {
		return throwsDecl;
	}

	public void setSignature(String signature) {
		this.signature = signature;
	}

	public String getSignature() {
		return signature;
	}
	
	public void setDeclaredInInterface(IDLInterface declaredInInterface) {
		this.declaredInInterface = declaredInInterface;
	}

	public IDLInterface getDeclaredInInterface() {
		return declaredInInterface;
	}

	public boolean isEqualsToOperation(IDLInterfaceOperation srcOperation) {
		boolean result = false;		
		if ( srcOperation.getName().equals(this.getName()) ) {
			if ( srcOperation.getParams().size() == this.getParams().size() ) {
				result = true;
				IDLInterfaceOperationParam srcParams[] = srcOperation.getParams().toArray( new IDLInterfaceOperationParam[0] );
				IDLInterfaceOperationParam params[] = this.getParams().toArray( new IDLInterfaceOperationParam[0] );

				for (int i=0; i < srcOperation.getParams().size(); i++ ) {
					IDLInterfaceOperationParam srcParam = srcParams[i];
					IDLInterfaceOperationParam param = params[i];
					if ( !param.getType().isEqualsToType(srcParam.getType()) ) {
						result = false;
						break;
					}
				}
			}
		}
		return result;
	}	
}
